home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / diverses / cexpress / screen / wrtend.asm < prev    next >
Encoding:
Assembly Source File  |  1989-05-03  |  2.9 KB  |  104 lines

  1. ;void  write_end(strg,col,row,length,color);
  2. ;  unsigned char  *strg,col,row,length,color;
  3.  
  4.     EXTRN  _memory_model:byte
  5.     EXTRN  _video_buffer:word
  6.     EXTRN  _snow_protect:byte
  7.     EXTRN  _error_code:byte
  8.  
  9. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  10.     ASSUME CS:_TEXT
  11.     PUBLIC _write_end
  12. _write_end proc near
  13.     push bp            ;
  14.     mov  bp,sp        ;set stack frame
  15.     push di            ;
  16.     push si            ;
  17.     cmp  _memory_model,0    ;near or far?
  18.     jle  begin        ;jump if near
  19.     inc  bp            ;else add 2 to BP
  20.     inc  bp            ;
  21. begin:    push ds            ;DS changed
  22.     cld            ;set direction flag
  23.     mov  ax,_video_buffer    ;fetch _video_buffer
  24.     mov  es,ax        ;ES pts to buffer
  25.     mov  bl,_snow_protect    ;get _snow_protect before change DS
  26.     cmp  _memory_model,2    ;data near or far?
  27.     jb   L0            ;jump if near
  28.     lds  si,dword ptr[bp+4] ;DS:SI pts to Strg
  29.     inc  bp            ;add 2 to BP since dword ptr    
  30.     inc  bp            ;
  31.     jmp  short L00        ;
  32. L0:    mov  si,[bp+4]        ;near case
  33. L00:    push si            ;must find string length
  34.     sub  cx,cx        ;count in CX
  35. L000:    inc  si            ;forward strg ptr
  36.     inc  cx            ;inc counter
  37.     cmp  byte ptr[si],0    ;end of string?
  38.     jne  L000        ;loop if not
  39.     pop  si            ;SI back to start of string
  40.     sub  ax,ax        ;
  41.     mov  al,[bp+8]        ;get ROW value
  42.     mov  byte ptr[bp+8],bl ;save _snow_protect
  43.     mov  byte ptr[bp+9],1    ;_error_code 1 = len(Strg) > Length
  44.     dec  ax            ;count from zero
  45.     mov  dl,160        ;160 bytes per line
  46.     mul  dl            ;times number rows
  47.     sub  dx,dx        ;
  48.     mov  dl,[bp+10]        ;move line length to DX
  49.     or   dx,dx        ;null?
  50.     jz   L1            ;quit if so
  51.     mov  byte ptr[bp+9],0    ;else 0 = no error
  52. L1:    cmp  dx,cx        ;Strg shorter?
  53.     jnae L2            ;jump ahead if so
  54.     sub  dx,cx        ;num chars at end of line
  55.     jmp  short L3        ;jump ahead
  56. L2:    mov  dx,0        ;else draw no extra chars
  57. L3:    sub  bx,bx        ;
  58.     mov  bl,[bp+6]        ;get COL value
  59.     mov  di,bx        ;
  60.     dec  di            ;count from zero
  61.     shl  di,1        ;double for attri bytes
  62.     add  di,ax        ;now ES:DI pts to lst pos
  63.     mov  ah,[bp+12]        ;get attribute
  64. L4:    lodsb            ;get a character
  65.     call WriteIt        ;write char and attri
  66.     loop L4            ;go do next
  67. L5:    mov  cx,dx        ;num chars at end of line
  68.     mov  al,32        ;space character
  69.     jcxz L7            ;jump if none to write
  70. L6:    call Writeit        ;write char and attribute
  71.     loop L6            ;go do next
  72. L7:    pop  ds            ;restore DS
  73.     mov  al,[bp+9]        ;fetch Errorcode
  74.     mov  _error_code,al    ;set it
  75.     pop  si            ;
  76.     pop  di            ;
  77.     pop  bp            ;
  78.     sti            ;reenable interrupts
  79.     cmp  _memory_model,0    ;quit
  80.     jle  quit        ;
  81.     db   0CBh        ;RET far
  82. quit:    ret            ;RET near
  83. _write_end endp
  84. Writeit    PROC            ;_snow_protect routine
  85.     push dx            ;save DX
  86.     cmp  byte ptr[bp+8],0    ;protect against snow?
  87.     je   R3            ;jump ahead if not
  88.     mov  dx,3dah        ;status byte address
  89.     mov  bx,ax        ;save char-attri in BX
  90. R1:    in   al,dx        ;get status byte
  91.     test al,1        ;test bit
  92.     jnz  R1            ;loop till 0
  93.     cli            ;disable interrupts
  94. R2:    in   al,dx        ;get status byte
  95.     test al,1        ;test bit
  96.     jz   R2            ;loop till 1
  97.     mov  ax,bx        ;return char-attri to AX
  98. R3:    stosw            ;write the character
  99.     pop  dx            ;restore DX
  100.     ret            ;
  101. WriteIt    endp
  102. _TEXT    ENDS
  103.     END
  104.